package br.com.karitza.gui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;
import br.com.karitza.exception.GeralException;
import br.com.karitza.gui.R;
import br.com.karitza.modelo.entidade.Imovel;
import br.com.karitza.modelo.negocio.RNImovel;

public class ListaTipos extends Activity implements OnClickListener {
	private final int SET_NEW_REQUEST = 0;
	private Button btRh,btRv,btNrh,btNrv,btGf;
	private RNImovel rn;
	private Imovel imovel;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		rn = new RNImovel(this);
		imovel = (Imovel)getIntent().getSerializableExtra("imovel");
		
		getWindow().requestFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

		setContentView(R.layout.lista_tipos);

		btRh = (Button) findViewById(R.id.btRh);
		btRv = (Button) findViewById(R.id.btRv);
		btNrh = (Button) findViewById(R.id.btNrh);
		btNrv = (Button) findViewById(R.id.btNrv);
		btGf = (Button) findViewById(R.id.btGf);
		
		btRh.setOnClickListener(this);
		btRv.setOnClickListener(this);
		btNrh.setOnClickListener(this);
		btNrv.setOnClickListener(this);
		btGf.setOnClickListener(this);
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		setResult(RESULT_OK);
		finish();
	}
	
	public void onClick(View v) {
		try {
			imovel.setTipo( rn.getTipo( ((Button)findViewById(v.getId())).getText().toString() ));
			Intent it = new Intent(this,ListaGrupos.class);
			it.putExtra("imovel", imovel);
			startActivityForResult(it, SET_NEW_REQUEST);
		} catch (GeralException e) {
			Toast.makeText(ListaTipos.this, e.getMessage(), Toast.LENGTH_LONG).show();
		}
	}
}
